package com.meizi.threalocad.controller;

/**
 * @author Administration
 * @date 2021/5/18 - 22:18 - 星期二
 * @project lambda-stuty
 * @package com.meizi.threalocd.controller
 * @by GGbomd猪猪侠
 */

public class TestInheritableThreadLocalController implements Runnable{

    //private static ThreadLocal<String> threadLocal = new ThreadLocal<>();

    private static InheritableThreadLocal<String> threadLocal = new InheritableThreadLocal<>();


    public static void main(String[] args) {
        System.out.println("----主线程设置值为\"主线程\"");
        threadLocal.set("主线程");
        System.out.println("----主线程设置后获取值：" + threadLocal.get());
        Thread tt = new Thread(new TestInheritableThreadLocalController());
        tt.start();
        System.out.println("----主线程结束");
    }
    @Override
    public void run() {
        System.out.println("----子线程设置值前获取：" + threadLocal.get());
        System.out.println("----新开线程设置值为\"子线程\"");
        threadLocal.set("子线程");
        System.out.println("----新开的线程设置值后获取：" + threadLocal.get());
    }
}
